import {
  BadRequestException,
  createParamDecorator,
  ExecutionContext,
} from '@nestjs/common';

export const PayloadMcuid = createParamDecorator(
  (data, ctx: ExecutionContext) => {
    const request = ctx.switchToHttp().getRequest();
    const mcuid = request.headers['mcuid'];
    const mcuid1 = request.headers['mcuid1'];
    if (!mcuid && !mcuid1) {
      throw new BadRequestException('mcuid header is missing');
    }
    return mcuid ?? mcuid1;
  },
);
